package bomberman.client;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Image;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;	
import javax.swing.JPanel;

/**
 * Class made to represent the board on the view.
 * 
 * @author Bart Verhoeven
 * @version 0.1
 *
 */
public class BoardView extends JPanel {

	/**
	 * version id
	 */
	private static final long serialVersionUID = 904474309133429664L;
	
	private TileView[][] tiles;
	
	private final Map<Object, Image> images;
	
	public BoardView(int width, int height) {
		this.images = new HashMap<Object, Image>();
		
		this.tiles = new TileView[width][height];
		
		loadImages();
		initLayout();
	}

	private void loadImages() {
		try {
			images.put(null, ImageIO.read(getClass().getResourceAsStream("../res/emptySquare.jpg")));
//			wallImage = ImageIO.read(getClass().getResourceAsStream("../res/wallImage.jpg"));
//			bomberImage = ImageIO.read(getClass().getResourceAsStream("../res/bomberImage.jpg"));
//			itemImage = ImageIO.read(getClass().getResourceAsStream("../res/itemImage.jpg"));
//			boxImage = ImageIO.read(getClass().getResourceAsStream("../res/boxImage.jpg"));
		} catch(IOException e) {
			System.out.println("error reading  images");
		}
	}

	private void initLayout() {
		this.setBorder(BorderFactory.createLineBorder(Color.black));
		this.setLayout(new GridLayout(tiles.length, tiles[0].length));
		for (int i = 0; i < tiles.length; i++) {
			for (int j = 0; j < tiles[i].length; j++) {
				tiles[i][j] = new TileView(images);
				this.add(tiles[i][j]);
			}
		}
			
	}
}
